package com.jeegit.ecms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeegit.common.annotation.Log;
import com.jeegit.common.enums.BusinessType;
import com.jeegit.ecms.domain.CmsCollection;
import com.jeegit.ecms.service.ICmsCollectionService;
import com.jeegit.common.core.controller.BaseController;
import com.jeegit.common.core.domain.AjaxResult;
import com.jeegit.common.utils.poi.ExcelUtil;
import com.jeegit.common.core.page.TableDataInfo;

/**
 * 合集管理Controller
 * 
 * @author jeegit
 * @date 2022-06-27
 */
@Controller
@RequestMapping("/ecms/collection")
public class CmsCollectionController extends BaseController
{
    private String prefix = "ecms/collection";

    @Autowired
    private ICmsCollectionService cmsCollectionService;

    @RequiresPermissions("ecms:collection:view")
    @GetMapping()
    public String collection()
    {
        return prefix + "/collection";
    }

    /**
     * 查询合集管理列表
     */
    @RequiresPermissions("ecms:collection:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsCollection cmsCollection)
    {
        startPage();
        List<CmsCollection> list = cmsCollectionService.selectCmsCollectionList(cmsCollection);
        return getDataTable(list);
    }

    /**
     * 导出合集管理列表
     */
    @RequiresPermissions("ecms:collection:export")
    @Log(title = "合集管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsCollection cmsCollection)
    {
        List<CmsCollection> list = cmsCollectionService.selectCmsCollectionList(cmsCollection);
        ExcelUtil<CmsCollection> util = new ExcelUtil<CmsCollection>(CmsCollection.class);
        return util.exportExcel(list, "合集管理数据");
    }

    /**
     * 新增合集管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合集管理
     */
    @RequiresPermissions("ecms:collection:add")
    @Log(title = "合集管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsCollection cmsCollection)
    {
        return toAjax(cmsCollectionService.insertCmsCollection(cmsCollection));
    }

    /**
     * 修改合集管理
     */
    @RequiresPermissions("ecms:collection:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsCollection cmsCollection = cmsCollectionService.selectCmsCollectionById(id);
        mmap.put("cmsCollection", cmsCollection);
        return prefix + "/edit";
    }

    /**
     * 修改保存合集管理
     */
    @RequiresPermissions("ecms:collection:edit")
    @Log(title = "合集管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsCollection cmsCollection)
    {
        return toAjax(cmsCollectionService.updateCmsCollection(cmsCollection));
    }

    /**
     * 删除合集管理
     */
    @RequiresPermissions("ecms:collection:remove")
    @Log(title = "合集管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsCollectionService.deleteCmsCollectionByIds(ids));
    }
}
